package com.lywz.core.web.struts;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.lywz.core.log.LogClerk;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.spring.SpringObjectFactory;

public class StrutsSpringObjectFactory extends SpringObjectFactory {

    private static final long serialVersionUID = -4167490320673765459L;

    @Inject
    public StrutsSpringObjectFactory(@Inject ServletContext servletContext) {
        LogClerk.sysout.info("initializing Struts-Spring intergration");
        ApplicationContext context = WebApplicationContextUtils
                .getWebApplicationContext(servletContext);
        if (context == null) {
            LogClerk.sysout
                    .info("@@@@@@@@@@@@@@@@@initializing Struts-Spring intergration@@@@@@@@@@@@@@");
            return;
        }

        setApplicationContext(context);

        setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);

        LogClerk.sysout.info(".......initializing Struts-Spring intergration end");
    }
}
